<template>
  <div style="padding: 12px">
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column label="管理员" width="180">
        <template slot-scope="scope">{{ scope.row.userid.userName }}</template>
      </el-table-column>
      <el-table-column prop="path" label="路径" width="180" />
      <el-table-column prop="params" label="参数" />
      <el-table-column prop="time" label="操作时间" width="180">
        <template slot-scope="scope">{{
          scope.row.time | formatTime
        }}</template>
      </el-table-column>
    </el-table>
    <el-row type="flex" justify="end" style="margin-top: 24px">
      <el-pagination
        @current-change="handlePageChange"
        :page-size="10"
        :pager-count="11"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      pageNum: 0,
      pageSize: 10,
      total: 0,
    };
  },
  created() {
    this.getData();
  },
  filters: {
    formatTime(value) {
      return new Date(parseInt(value))
        .toLocaleString()
        .replace(/:\d{1,2}$/, " ");
    },
  },
  methods: {
    async getData() {
      let res = await this.axios("logs", {
        params: {
          pageSize: this.pageSize,
          pageNum: this.pageNum,
        },
      });
      this.total = res.data.total;
      this.tableData = res.data.data;
    },
    handlePageChange(pageNum) {
      this.pageNum = pageNum - 1;
      this.getData();
    },
  },
};
</script>

<style>
</style>